package com.ruoyi.web.controller.wbgame;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wbgame.domain.WbQuestionType;
import com.ruoyi.wbgame.service.IWbQuestionTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题目类型Controller
 * 
 * @author guguofu
 * @date 2021-04-17
 */
@Controller
@RequestMapping("/wbgame/questionType")
public class WbQuestionTypeController extends BaseController
{
    private String prefix = "wbgame/questionType";

    @Autowired
    private IWbQuestionTypeService wbQuestionTypeService;

    @RequiresPermissions("wbgame:questionType:view")
    @GetMapping()
    public String questionType()
    {
        return prefix + "/questionType";
    }

    /**
     * 查询题目类型列表
     */
    @RequiresPermissions("wbgame:questionType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WbQuestionType wbQuestionType)
    {
        startPage();
        List<WbQuestionType> list = wbQuestionTypeService.selectWbQuestionTypeList(wbQuestionType);
        return getDataTable(list);
    }

    /**
     * 导出题目类型列表
     */
    @RequiresPermissions("wbgame:questionType:export")
    @Log(title = "题目类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WbQuestionType wbQuestionType)
    {
        List<WbQuestionType> list = wbQuestionTypeService.selectWbQuestionTypeList(wbQuestionType);
        ExcelUtil<WbQuestionType> util = new ExcelUtil<WbQuestionType>(WbQuestionType.class);
        return util.exportExcel(list, "questionType");
    }

    /**
     * 新增题目类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存题目类型
     */
    @RequiresPermissions("wbgame:questionType:add")
    @Log(title = "题目类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WbQuestionType wbQuestionType)
    {
        return toAjax(wbQuestionTypeService.insertWbQuestionType(wbQuestionType));
    }

    /**
     * 修改题目类型
     */
    @GetMapping("/edit/{typeId}")
    public String edit(@PathVariable("typeId") Long typeId, ModelMap mmap)
    {
        WbQuestionType wbQuestionType = wbQuestionTypeService.selectWbQuestionTypeById(typeId);
        mmap.put("wbQuestionType", wbQuestionType);
        return prefix + "/edit";
    }

    /**
     * 修改保存题目类型
     */
    @RequiresPermissions("wbgame:questionType:edit")
    @Log(title = "题目类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WbQuestionType wbQuestionType)
    {
        return toAjax(wbQuestionTypeService.updateWbQuestionType(wbQuestionType));
    }

    /**
     * 删除题目类型
     */
    @RequiresPermissions("wbgame:questionType:remove")
    @Log(title = "题目类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wbQuestionTypeService.deleteWbQuestionTypeByIds(ids));
    }
}
